package com.vip.jwt.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vip.jwt.common.entity.R;
import com.vip.jwt.entity.AppVersion;
import com.vip.jwt.service.AppVersionService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author vip
 * @since 2021-07-24
 */
@RestController
@RequestMapping("/api/app/version")
public class AppVersionController {

    @Resource
    private AppVersionService appVersionService;

    @PostMapping("/check")
    public Object checkUpdate(@RequestBody AppVersion appVersion){
        AppVersion findAppVersion = appVersionService.checkUpdate(appVersion);
        return R.ok().data("data",findAppVersion);
    }

    @PostMapping
    public Object add(@RequestBody AppVersion appVersion){
        appVersionService.save(appVersion);
        return R.ok();
    }

    @DeleteMapping("/{id}")
    public Object delete(@PathVariable String id){
        appVersionService.removeById(id);
        return R.ok();
    }

    @PutMapping
    public Object update(@RequestBody AppVersion appVersion){
        appVersionService.updateById(appVersion);
        return R.ok();
    }

    @GetMapping
    public Object list(){
        List<AppVersion> appVersions = appVersionService.list();
        return R.ok().data("data",appVersions);
    }

    @GetMapping("/{page}/{limit}")
    public Object page(@PathVariable Long page,@PathVariable Long limit){
        Page<AppVersion> appVersionPage = new Page<>(page,limit);
        QueryWrapper<AppVersion> appVersionQueryWrapper = new QueryWrapper<>();
        appVersionQueryWrapper.orderByDesc("create_time");
        appVersionPage = appVersionService.page(appVersionPage,appVersionQueryWrapper);
        return R.ok().data("data",appVersionPage);
    }

}

